package com.uwlaser.modules.system.service.impl;

import com.uwlaser.base.impl.CommonServiceImpl;
import com.uwlaser.modules.system.domain.RolesFactoryModels;
import com.uwlaser.modules.system.service.RolesFactoryModelsService;
import com.uwlaser.modules.system.service.mapper.RolesFactoryModelsMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class RolesFactoryModelsServiceImpl extends CommonServiceImpl<RolesFactoryModelsMapper, RolesFactoryModels> implements RolesFactoryModelsService {
    @Override
    public List<Integer> queryMenuIdByRoleId(Long id) {
        return lambdaQuery().eq(RolesFactoryModels::getRoleId, id).list().stream().map(RolesFactoryModels::getFactoryModelId)
                .collect(Collectors.toList());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeRoleId(Long id) {
        return lambdaUpdate().eq(RolesFactoryModels::getRoleId, id).remove();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeFactoryModelId(Integer id) {
        return lambdaUpdate().eq(RolesFactoryModels::getFactoryModelId, id).remove();
    }
}
